package com.zcxy.fast.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcxy.fast.anotation.Log;
import com.zcxy.fast.bean.PageQuery;
import com.zcxy.fast.bean.Response;
import com.zcxy.fast.entity.MainTable;
import com.zcxy.fast.vo.MainTableVo;
import com.zcxy.fast.service.IMainTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.*;
import com.zcxy.fast.bean.TreeNode;

/**
 * 主表Controller
 *
 * @author zcc
 * @email  860474958@qq.com
 * @date   2021-01-15 14:00:36
 */
@RestController
@RequestMapping("/api/mainTable")
@Api(tags = "主表管理")
@Slf4j
public class MainTableController {
    @Autowired
    private IMainTableService iMainTableService;

    @Log("获取主表数据--分页")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(主表)分页数据列表", notes = "获取(主表)分页数据列表")
    public Response<IPage<MainTableVo>> queryPageList(@RequestBody PageQuery<MainTable> queryVo) {
        return Response.ok(iMainTableService.queryPageList(queryVo));
    }

    @Log("获取主表数据-列表")
    @PostMapping(value = "/queryList")
    @ApiOperation(value = "获取主表数据-列表", notes = "获取主表数据-列表")
    public Response<List<MainTableVo>> queryList(@RequestBody MainTable mainTable) {
        return Response.ok(iMainTableService.queryList( mainTable));
    }


    @Log("添加主表数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "添加主表数据", notes = "添加主表数据")
    public Response addMainTable(@RequestBody @Validated @NotNull MainTable queryVo) {
        iMainTableService.addMainTable(queryVo);
        return Response.ok();
    }


    @Log("修改主表数据")
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改主表数据", notes = "修改主表数据")
    public Response updateMainTable(@RequestBody @Validated @NotNull MainTable queryVo) {
        iMainTableService.updateMainTable(queryVo);
        return Response.ok();
    }


    @Log(value = "批量删除主表")
    @ApiOperation("批量删除主表")
    @PostMapping("/dels")
    public Response deleteByIds(@RequestBody List<String> ids) {
        iMainTableService.removeAllMainTable(ids);
        return Response.ok();
    }

}
